package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    NursingProjectMapper nursingProjectMapper;


    @Override
    public PageResponse<NursingProjectVo> selectByPage(Integer pageNum,
                                                       Integer pageSize,
                                                       String name,
                                                       Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> page = nursingProjectMapper.selectByPage(name, status);
        PageResponse<NursingProjectVo> pageResponse = PageResponse.of(page, NursingProjectVo.class);
        return pageResponse;
    }

    @Override
    public void addNursingProject(NursingProjectDto nursingProjectdto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectdto, NursingProject.class);
        nursingProjectMapper.addNursingProject(nursingProject);
    }

    @Override
    public NursingProjectVo getNursingProjectById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.getNursingProjectById(id);
        if (nursingProject != null) {
            NursingProjectVo nursingProjectVo = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
            return nursingProjectVo;
        }
        return null;
    }

    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectdto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectdto, NursingProject.class);
        nursingProjectMapper.updateNursingProject(nursingProject);
    }

    @Override
    public void deleteNursingProject(Long id) {

        nursingProjectMapper.deleteNursingProject(id);
    }

    @Override
    public void updateNursingProjectStatus(Long id, Integer status) {

        nursingProjectMapper.updateNursingProjectStatus(id, status);
    }

    @Override
    public List<NursingProjectVo> getAllNursingProject() {
        List<NursingProject> nursingProjects = nursingProjectMapper.getAllNursingProject();
        if (nursingProjects != null) {
            List<NursingProjectVo> nursingProjectVos = BeanUtil.copyToList(nursingProjects, NursingProjectVo.class);
            return nursingProjectVos;
        }
        return null;
    }
}
